package com.social.servlet;

import com.social.dao.LogDao;
import com.social.model.Reply;
import com.social.model.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Add_Reply", value = "/Add_Reply")
public class Add_Reply extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        重新部署Session中传的值会没有，所以你要在部署后重新登录
        HttpSession session = request.getSession();
            int c_id = Integer.parseInt(request.getParameter("c_id"));
            String r_content = request.getParameter("content");

            User user = (User)session.getAttribute("user");
            String nick_name = user.getNickname();
            String avatar = user.getAvatar();

        Reply r = new Reply(c_id,nick_name,avatar,r_content);

            LogDao l = new LogDao();
            l.insertReply(r);


    }
}
